package com.hdaccp.xingmu.config;//package com.hdaccp.config;
//
//import com.hdaccp.MyRealm.Realm;
//import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
//import org.apache.shiro.web.mgt.CookieRememberMeManager;
//import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
//import org.apache.shiro.web.servlet.SimpleCookie;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.util.LinkedHashMap;
//import java.util.Map;
//
//@Configuration
//
//public class ShiroConfig {
//    @Bean
//    public Realm Realm(){
//        Realm myRealm = new Realm() ;
//        return myRealm ;
//    }
//
//    @Bean
//    public SimpleCookie rememberMeCookie() {
//        //System.out.println("ShiroConfiguration.rememberMeCookie()");
//        //这个参数是cookie的名称，对应前端的checkbox的name = rememberMe
//        SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
//        //<!-- 记住我cookie生效时间30天 ,单位秒;-->
//        simpleCookie.setMaxAge(10);
//        return simpleCookie;
//    }
//
//    @Bean
//    public CookieRememberMeManager rememberMeManager() {
//        //System.out.println("ShiroConfiguration.rememberMeManager()");
//        CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager();
//        cookieRememberMeManager.setCookie(rememberMeCookie());
//        //rememberMe cookie加密的密钥 建议每个项目都不一样 默认AES算法 密钥长度(128 256 512 位)
//        //  cookieRememberMeManager.setCipherKey(Base64.decode("2AvVhdsgUs0FSA3SDFAdag=="));
//        return cookieRememberMeManager;
//    }
//
//
//
//    @Bean
//    public DefaultWebSecurityManager getDefaultWebSecurityManager(){
//        DefaultWebSecurityManager defaultWebSecurityManager = new DefaultWebSecurityManager() ;
//        defaultWebSecurityManager.setRealm(Realm());
//
//        defaultWebSecurityManager.setRememberMeManager(rememberMeManager());
//
//        return defaultWebSecurityManager ;
//    }
//    @Bean
//    public ShiroFilterFactoryBean getShiroFilterFactoryBean(){
//        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean() ;
//
//        //
//        shiroFilterFactoryBean.setSecurityManager(getDefaultWebSecurityManager());
//
//        Map<String,String> map = new LinkedHashMap<String,String>() ;
//        //定义可以直接访问的资源
//        map.put("/index.jsp","anon") ;
//        map.put("/user/login","anon") ;
//        //取消认证
//        map.put("/logout","logout") ;
//
//        //
//        map.put("/add.jsp","perms[user:add]") ;
//
//
//        map.put("/**","user") ;
//
//
//        shiroFilterFactoryBean.setFilterChainDefinitionMap(map);
//        // shiroFilterFactoryBean.setLoginUrl("/login.jsp");
//        shiroFilterFactoryBean.setUnauthorizedUrl("/unauth.jsp");
//        return shiroFilterFactoryBean ;
//    }
//
//
//}
